/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.sadhar.sipp.jenispos;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.sadhar.sia.common.ClassConnection;

/**
 *
 * @author hendro
 */
public class JenisPosDAOImpl implements JenisPosDAO {

    public JenisPosDAOImpl(){
        ClassConnection.getTransactionProxyFactoryBean().setTarget(this);
    }

    public List<JenisPos> list() throws Exception {
        return ClassConnection.getJdbc().queryForList("SELECT * FROM ppmk.jenisPos");
    }

    public List<JenisPos> list(String key) throws Exception {        
        String sql = "SELECT * FROM ppmk.jenisPos WHERE kodeJenisPos LIKE ? OR jenisPos LIKE ?";
        List<JenisPos> list = new ArrayList<JenisPos>();
        List<Map> rows = ClassConnection.getJdbc().queryForList(sql, new Object[]{key,"%" + key + "%"});
        for (Map m : rows) {
            JenisPos jenisPos = new JenisPos();
            jenisPos.setKodeJenisPos(Integer.parseInt(m.get("kodeJenisPos").toString()));
            jenisPos.setJenisPos(m.get("jenisPos").toString());
            jenisPos.setNamaTabelSubPos(m.get("namaTabelSubPos").toString());
            list.add(jenisPos);
        }
        return list;
    }

}
